<template>
	<div class="export-dialog-view" v-loading="pageLoading">
		<div class="export-dialog">
			<div class="left-lay">
				<div class="split-title">{{ title }}</div>
				<div class="left-line">
					<div class="line-title">
						{{ $t("message.bhView.leftComponents.device") }}
					</div>
					<div class="line-value">{{ $store.state.plantName }}</div>
				</div>

				<div class="left-line">
					<div class="line-title">
						{{ $t("message.bhView.leftComponents.object") }}
					</div>
					<div class="line-value">
						{{
							$store.state.macType == 1
								? $t("message.bhView.leftComponents.machine")
								: $t("message.bhView.leftComponents.piping")
						}}
					</div>
				</div>

				<div class="left-line">
					<div class="line-title">
						{{ $t("message.reportFrom.exportDialog.title_c") }}
					</div>
					<div class="line-value">{{ fileTypeStr }}</div>
				</div>
				<div class="left-draw" id="left-draw"></div>
			</div>

			<div class="tip-lay"></div>

			<div class="right-lay">
				<div class="split-title text-right">
					<i class="el-icon-close" @click="CloseExprotDiloag"></i>
				</div>
				<div class="split-title">
					{{ $t("message.reportFrom.exportDialog.title_l") }}
				</div>
				<!-- <div class="right-line">
					<div class="line-title">
						時期指定
					</div>

				</div>
				<div class="line-content">
					<el-date-picker v-model="Data.From" type="month" :format="format" :value-format="format"
						placeholder=" " class="ipt picker">
					</el-date-picker>
					<span>~</span>
					<el-date-picker v-model="Data.To" type="month" :format="format" :value-format="format"
						placeholder=" " class="ipt picker orange">
					</el-date-picker>
				</div> -->

				<div class="right-line">
					<div class="line-title" style="width:150px;">
						出力形式、出力期間
					</div>
				</div>
				<div class="line-content" style="padding-left:12px;">
					<el-radio :label="1" v-model="Data.ExcuteType"
						@change="Data.Year = 10, Data.Month = null">年表示</el-radio>
					<el-input class="ipt picker" v-model="Data.Year" :disabled="Data.ExcuteType != 1"
						:class="Data.ExcuteType != 1 ? '' : 'orange'"
						@input="iptRuleFn('year'), Data.Year = $setMyNum(Data.Year, '2 - 0')"></el-input>
					<span>年分</span>
				</div>
				<div class="line-content" style="padding-left:12px;">
					<el-radio :label="2" v-model="Data.ExcuteType"
						@change="Data.Month = 2, Data.Year = null">月表示</el-radio>
					<el-input class="ipt picker" v-model="Data.Month" :disabled="Data.ExcuteType != 2"
						:class="Data.ExcuteType != 2 ? '' : 'orange'"
						@input="iptRuleFn('month'), Data.Month = $setMyNum(Data.Month, '2 - 0')"></el-input>
					<span>月分</span>
				</div>

				<div class="right-line">
					<div class="line-title">
						休止点出力
					</div>
				</div>
				<div class="line-content" style="padding-left:12px;">
					<el-radio-group v-model="Data.RestPoint">
						<el-radio :label="1">出力する</el-radio>
						<el-radio :label="2">出力しない</el-radio>
					</el-radio-group>
				</div>

				<div class="right-line bottom-border" style="border-top: 1px solid #f0f0f0;margin-top: 10px;;">
					<div class="line-title">
						{{ $t("message.reportFrom.exportDialog.title_j") }}
					</div>
					<!-- <div class="line-content"> -->
					<!-- <el-select v-model="operDate" class="select-ipt orange" style="margin: 0 8px 0 16px"
							placeholder=" ">
							<el-option v-for="item in LifeAssBaseDate" :key="item.value" :label="item.label"
								:value="item.value">
							</el-option>
						</el-select> -->
					<el-select v-model="Data.StdDate" class="select-ipt" placeholder=" ">
						<el-option v-for="item in StdDateCom" :key="item" :label="item" :value="item">
						</el-option>
					</el-select>
					<!-- </div> -->
				</div>

			</div>
			<footer class="footer-view">
				<div class="">
					<div class="line-title" style="width: 100%">
						{{ $t("message.reportFrom.exportDialog.tip") }}
					</div>
				</div>
				<div>
					<el-button @click="CloseExprotDiloag">Cancel</el-button>
					<el-button type="primary" @click="okFn">OK</el-button>
				</div>
			</footer>
		</div>
	</div>
</template>

<script>
import {
	ExThickMeasurementResOverviewExcel, GetThickDeterResLifeAssBaseDate
} from "@/api/api";
import * as svg_opt from "@/utils/svg_opt.js";
import { getLocalStorage } from "@/utils/storage";

export default {
	props: ["title", "fileTypeStr", "selectMacData", "fileRadio"],
	name: "F_D_Export",
	data() {
		return {
			pageLoading: false,
			format: "yyyy-MM",
			StdDateCom: [],
			Data: {
				From: '',
				To: '',
				ExcuteType: 1,
				Year: 10,
				Month: null,
				RestPoint: 2,
				StdDate: '',
			}
		};
	},
	components: {},
	watch: {},
	methods: {
		async okFn() {
			this.pageLoading = true;
			let MacNumb = [];
			this.selectMacData.forEach((i, v) => {
				MacNumb.push(i.macName);
				// MacNumb.push(i.realMacCode);
			})
			let dataJson = {
				PltCode: this.selectMacData[0].pltCode,
				MacType: this.selectMacData[0].macType,
				MacNumb,
				...this.Data
			};
			let res = await ExThickMeasurementResOverviewExcel(dataJson);
			this.pageLoading = false;
			if (res.data.code != 0) {
				console.log("s5fd1");
				this.$alert(res.data.msg, '', {
					confirmButtonText: 'OK',
					type: 'warning',
					callback: action => {
					}
				})
				return
			}
			this.$emit("CloseExprotDiloag");
			window.open(res.data.data);
		},
		CloseExprotDiloag() {
			this.$emit("CloseExprotDiloag");
		},
		iptRuleFn(tip) {
			if (tip == 'year') {
				this.Data.Year = Number(this.Data.Year) > 30 ? 30 : Number(this.Data.Year);
				this.Data.Year = !Number(this.Data.Year) ? null : Number(this.Data.Year);
			}
			if (tip == 'month') {
				this.Data.Month = Number(this.Data.Month) > 10 ? 10 : Number(this.Data.Month);
				this.Data.Month = !Number(this.Data.Month) ? null : Number(this.Data.Month);
			}
		},
		async GetThickDeterResLifeAssBaseDateFn() {
			let dataJson = {
				PltCode: this.selectMacData[0].pltCode,
			};
			let res = await GetThickDeterResLifeAssBaseDate(dataJson);
			this.StdDateCom = res.data.data;
			this.Data.StdDate = this.StdDateCom[6];
		},
		initFn() {
			let nowYear = new Date().getFullYear();
			let nowMonth =
				new Date().getMonth() + 1 < 10
					? "0" + (new Date().getMonth() + 1)
					: new Date().getMonth() + 1;
			this.Data.To = `${nowYear}-${nowMonth}`;

			this.GetThickDeterResLifeAssBaseDateFn();
		},
	},
	created() {

	},
	mounted() {
		this.initFn();
	},
	beforeDestroy() { },
	destroyed() { },
};
</script>

<style lang="scss" scoped>
.export-dialog-view {
	position: fixed;
	width: 100%;
	height: 100%;
	left: 0;
	top: 0;
	z-index: 6;
}

.export-dialog {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	width: 750px;
	height: 505px;
	// height: 292px;
	background: #ffffff;
	box-shadow: 0px 12px 48px 16px rgba(0, 0, 0, 0.05),
		0px 9px 28px 0px rgba(0, 0, 0, 0.08),
		0px 6px 16px -8px rgba(0, 0, 0, 0.15);
	display: flex;
	flex-direction: row;
	padding: 0 12px;
}

.left-lay {
	position: relative;
	width: 40%;
	height: 100%;
	// border-right: 1px solid #ccc;
	display: flex;
	flex-direction: column;
	// background-color: blanchedalmond;

	.left-line {
		width: 100%;
		display: flex;
		flex-direction: row;
		align-items: center;
		padding: 0px 20px;
		padding-top: 10px;

		.line-title {
			font-size: 14px;
			font-weight: 700;
			color: rgba(0, 0, 0, 0.85);
			line-height: 22px;
		}

		.line-value {
			font-size: 14px;
			font-weight: 400;
			color: #7b7b7b;
			line-height: 22px;
			margin-left: 10px;
		}
	}

	.left-draw {
		position: absolute;
		top: 100vh;
		width: 750px;
		height: 611px;
		// flex-grow: 1;
		// flex-shrink: 1;
		background-color: bisque;
	}
}

.tip-lay {
	background: red;
	width: 7px;
	border-radius: 4px;
	background: #ccc;
	margin-top: 46px;
	margin: 46px 15px 85px 15px;
}

.right-lay {
	position: relative;
	width: 70%;
	height: 100%;
	display: flex;
	flex-direction: column;

	.el-icon-close {
		font-size: 16px;
		cursor: pointer;
		width: 46px;
		height: 45px;
		line-height: 45px;
	}

	.right-block-container {
		width: 100%;
		display: flex;
		flex-direction: column;
	}

	.text-right {
		padding: 0 !important;
		text-align: right;
	}

	.right-line {
		width: 100%;
		display: flex;
		flex-direction: row;
		align-items: center;
		padding: 0px 12px;
		padding-top: 17px;

		.line-title {
			font-size: 14px;
			font-weight: 700;
			color: rgba(0, 0, 0, 0.85);
			line-height: 22px;
			text-align: left;
			margin-right: 10px;
			width: 110px;
		}

		.line-content {
			height: 20px;
			flex-grow: 1;
			flex-shrink: 1;
			display: flex;
			flex-direction: row;
			align-items: center;
		}



		.divider {
			width: 100%;
			height: 1px;
			background-color: #f0f0f0;
		}
	}

	.ipt {
		//     width: 368px;
		width: 100%;
		height: 32px;

		::v-deep .el-input__inner {
			width: 100%;
			height: 32px;
		}

		::v-deep .el-input__inner:focus {
			border: 1px solid #dcdfe6;
		}

		::v-deep .el-input__icon {
			line-height: 32px;
			color: #909399;
		}

		::v-deep .el-input__suffix {
			width: 32px;
			right: 0;
			background: #dee0e3;
		}
	}

	.line-content {
		padding-top: 10px;
	}

	.picker {
		width: 130px;
		margin: 0px 10px;

		::v-deep .el-input__inner {
			width: 130px;
		}

		::v-deep .el-input__suffix {
			background: transparent;
		}
	}

	.orange {
		::v-deep .el-input__inner {
			// width: 130px;
			background-color: #FFDEACFF;
		}
	}

	.right-line.bottom-border {
		padding-bottom: 10px;
		// border-bottom: 1px solid #f0f0f0;
	}

	.flex-row {
		flex-direction: row;
	}

	.flex-column {
		flex-direction: column;
	}
}

.split-title {
	width: 100%;
	font-size: 16px;
	font-weight: 700;
	color: rgba(0, 0, 0, 0.85);
	line-height: 22px;
	padding: 12px 12px;
	border-bottom: 1px solid #f0f0f0;
}

.footer-view {
	width: calc(100% - 30px);
	box-sizing: border-box;
	position: absolute;
	z-index: 10;
	bottom: 16px;
	// padding: 0 15px;
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: space-between;
	// background-color: red;
	padding-top: 17px;
	border-top: 1px solid #f0f0f0;
	font-size: 16px;
	font-weight: 700;

	button {
		width: 82px !important;
		height: 32px;
		// background: #ffffff;
		// border: 1px solid #d9d9d9;
		margin-left: 12px;
		border-radius: 4px;
		font-size: 14px;
		font-weight: 500;
		line-height: 0;
	}

	button:nth-child(2) {
		// background: #106ebe;
		// color: #fff;
	}
}

.select-ipt {
	height: 32px;

	::v-deep .el-input__inner {
		width: 100%;
		height: 32px;
		// line-height: 32px;
	}

	::v-deep .el-input__inner:focus {
		border: 1px solid #dcdfe6;
	}

	::v-deep .el-input__icon {
		line-height: 32px;
		// color: #909399;
	}

	// ::v-deep .el-input__suffix {
	// 	width: 32px;
	// 	right: 0;
	// 	background: #dee0e3;
	// }
}

.p0 {
	padding: 12px 0;
}
</style>
